The Art of Mac Malware, Volume 2 (for caswal eraq) by Patrick Wardle
Author:Patrick Wardle
Language: eng
Format: epub
Publisher: No Starch Press
Identifying the Responsible Process
Identifying the process responsible for a DNS request is essential to detecting malware, yet DNS monitors that arenât host-based canât provide this information. For example, requests from trusted system processes are likely safe, while requests from, say, a persistent, unnotarized process such as iWebUpdate should be closely scrutinized.
Now Iâll show you how to obtain the ID of the responsible process using information provided by the NetworkExtension framework. The flow object passed into the extension via the handleNewFlow: delegate method contains an instance variable named metaData whose type is NEFlowMetaData. Consulting the NEFlowMetaData.h file (found in NetworkExtension.framework/Versions/A/Headers/) reveals that it contains a property named sourceAppAuditToken with the responsible processâs audit token.
From this audit token, we can extract the responsible processâs ID and securely obtain its path using SecCode* APIs. Listing 7-9 implements this technique.
CFURLRef path = NULL; SecCodeRef code = NULL; audit_token_t* auditToken = (audit_token_t*)flow.metaData.sourceAppAuditToken.bytes; ⶠpid_t pid = audit_token_to_pid(*auditToken); ⷠSecCodeCopyGuestWithAttributes(NULL, (__bridge CFDictionaryRef _Nullable)(@{(_bridge NSString*)kSecGuestAttributeAudit:flow.metaData.sourceAppAuditToken}), kSecCSDefaultFlags, &code); ⸠SecCodeCopyPath(code, kSecCSDefaultFlags, &path); ⹠// Do something with the process ID and path. CFRelease(path); CFRelease(code);
Listing 7-9: Obtaining the responsible processâs ID and path from a network flow
First, we initialize a pointer to an audit token. As noted, the sourceAppAuditToken contains this token in the form of an NSData object. To get a pointer to the audit tokenâs actual bytes, we use the bytes property of the NSData class â¶. With this pointer, we can extract the associated process ID via the audit_token_to_pid function â·. Next, we obtain a code reference from the audit token ⸠and then invoke the SecCodeCopyPath function to obtain the processâs path â¹.
Itâs worth noting that the SecCodeCopyGuestWithAttributes API can fail, for example, if the process has self-deleted. This case is both very unusual and likely indicative of a malicious process. Regardless, youâll have to defer to other, less certain methods of obtaining the processâs path, such as examining the processâs arguments, which can be surreptitiously modified.
From the flow, we can also extract the responsible processâs code signing identifier, which can help classify the process as either benign or something to investigate further. This identifier is in the flowâs sourceAppSigningIdentifier attribute. Listing 7-10 extracts it.
NSString* signingID = flow.metaData.sourceAppSigningIdentifier;
Listing 7-10: Extracting code signing information from a network flow
As noted earlier in this chapter, the DNS monitoring process Iâve described thus far would fail to detect malware such as Dummy, which connects directly to an IP address. To detect such threats, letâs expand our monitoring capabilities to examine all network traffic.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
What's Done in Darkness by Kayla Perrin(26765)
The Ultimate Python Exercise Book: 700 Practical Exercises for Beginners with Quiz Questions by Copy(20323)
D:\Jan\FTP\HOL\Work\Alien Breed - Tower Assault CD32 Alien Breed II - The Horror Continues Manual 1.jpg by PDFCreator(20148)
De Souza H. Master the Age of Artificial Intelligences. The Basic Guide...2024 by Unknown(20148)
The Fifty Shades Trilogy & Grey by E L James(19231)
Shot Through the Heart: DI Grace Fisher 2 by Isabelle Grey(19217)
Shot Through the Heart by Mercy Celeste(19078)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 10 by Isuna Hasekura and Jyuu Ayakura(17258)
Python GUI Applications using PyQt5 : The hands-on guide to build apps with Python by Verdugo Leire(17197)
Peren F. Statistics for Business and Economics...Essential Formulas 3ed 2025 by Unknown(17038)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 03 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16960)
Wolf & Parchment: New Theory Spice & Wolf, Vol. 01 by Isuna Hasekura and Jyuu Ayakura & Jyuu Ayakura(16589)
The Subtle Art of Not Giving a F*ck by Mark Manson(14548)
The 3rd Cycle of the Betrayed Series Collection: Extremely Controversial Historical Thrillers (Betrayed Series Boxed set) by McCray Carolyn(14281)
Stepbrother Stories 2 - 21 Taboo Story Collection (Brother Sister Stepbrother Stepsister Taboo Pseudo Incest Family Virgin Creampie Pregnant Forced Pregnancy Breeding) by Roxi Harding(13928)
Scorched Earth by Nick Kyme(12917)
Drei Generationen auf dem Jakobsweg by Stein Pia(11115)
Suna by Ziefle Pia(11038)
Scythe by Neal Shusterman(10505)